package com.faxsun.profile.core.domain;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.broadleafcommerce.common.presentation.AdminPresentation;
import org.broadleafcommerce.common.presentation.client.VisibilityEnum;
import org.broadleafcommerce.profile.core.domain.Customer;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import com.faxsun.core.tool.IDCardValidator;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "FS_BLC_IDCARD")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = "blOrderElements")
public class FSReceiverImpl implements FSReceiver {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5100515991704945275L;

	@Id
	@GeneratedValue(generator = "PhoneId")
	@GenericGenerator(name = "PhoneId", strategy = "org.broadleafcommerce.common.persistence.IdOverrideTableGenerator", parameters = {
			@Parameter(name = "segment_value", value = "FSReceiverImpl"),
			@Parameter(name = "entity_name", value = "org.broadleafcommerce.profile.core.domain.FSReceiverImpl") })
	@Column(name = "IDCARD_ID")
	protected Long id;

	@Column(name = "IDCARD_NAME")
	protected String name;

	@Column(name = "IDCARD_IDNUM")
	protected String idCard;

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, targetEntity = FSCustomerImpl.class, optional = true)
	@JoinColumn(name = "CUSTOMER_ID")
	@AdminPresentation(excluded = true, visibility = VisibilityEnum.HIDDEN_ALL)
	protected Customer customer;

	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String name) {
		this.name = name;

	}

	@Override
	public String getIdCard() {
		return this.idCard;
	}

	@Override
	public void setIdCard(String idCard) {
		this.idCard = idCard;

	}

	@Override
	public boolean isIdValidate() {
		String result = IDCardValidator.IDCardValidate(this.idCard);

		if (result.isEmpty()) {
			return true;
		}
		return false;
	}

	@Override
	public long getId() {
		return this.id;
	}

	@Override
	public void setId(long id) {

		this.id = id;
	}

	@Override
	public Customer getCustomer() {
		return this.customer;
	}

	@Override
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

}
